package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysFormMapper;
import com.ruoyi.system.domain.SysForm;
import com.ruoyi.system.service.ISysFormService;

/**
 * 单Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-31
 */
@Service
public class SysFormServiceImpl implements ISysFormService 
{
    @Autowired
    private SysFormMapper sysFormMapper;

    /**
     * 查询单
     * 
     * @param formId 单主键
     * @return 单
     */
    @Override
    public SysForm selectSysFormByFormId(Long formId)
    {
        return sysFormMapper.selectSysFormByFormId(formId);
    }

    /**
     * 查询单列表
     * 
     * @param sysForm 单
     * @return 单
     */
    @Override
    public List<SysForm> selectSysFormList(SysForm sysForm)
    {
        return sysFormMapper.selectSysFormList(sysForm);
    }

    /**
     * 新增单
     * 
     * @param sysForm 单
     * @return 结果
     */
    @Override
    public int insertSysForm(SysForm sysForm)
    {
        sysForm.setCreateTime(DateUtils.getNowDate());
        return sysFormMapper.insertSysForm(sysForm);
    }

    /**
     * 修改单
     * 
     * @param sysForm 单
     * @return 结果
     */
    @Override
    public int updateSysForm(SysForm sysForm)
    {
        sysForm.setUpdateTime(DateUtils.getNowDate());
        return sysFormMapper.updateSysForm(sysForm);
    }

    /**
     * 批量删除单
     * 
     * @param formIds 需要删除的单主键
     * @return 结果
     */
    @Override
    public int deleteSysFormByFormIds(Long[] formIds)
    {
        return sysFormMapper.deleteSysFormByFormIds(formIds);
    }

    /**
     * 删除单信息
     * 
     * @param formId 单主键
     * @return 结果
     */
    @Override
    public int deleteSysFormByFormId(Long formId)
    {
        return sysFormMapper.deleteSysFormByFormId(formId);
    }


    @Override
    public AjaxResult listSelect() {

        List<SysForm> formList = sysFormMapper.selectSysFormList(null);

        List<String> formNameList = formList.stream().map(SysForm::getFormName).distinct().collect(Collectors.toList());

        return AjaxResult.success(formNameList);
    }
}
